package com.abc.chatprj;

import jakarta.servlet.*;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.*;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

@WebServlet("/chat/send")
public class SendServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String msg = request.getParameter("msg");

        Object me = request.getSession().getAttribute("myself");
        Object obj = this.getServletContext().getAttribute("msgs");
        List<String> list = null;
        if(obj == null) {
            list = new ArrayList<String>();

        }else{
            list = (List<String>) obj;
        }
        list.add(me + "说："+msg);
        this.getServletContext().setAttribute("msgs", list);

        response.sendRedirect("send.jsp");
    }
}
